home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTime.z / RWTime
Encoding:
Text File  |  2002-10-03  |  19.9 KB  |  595 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTime - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/rwtime.h>
  13.  
  14.  
  15.  
  16.               RWTime a;   // Construct with current time
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      Class RRRRWWWWTTTTiiiimmmmeeee represents a time, stored as the number of seconds since
  23.      00:00:00 January 1, 1901 UTC.  See Section 8 for how to set the time zone
  24.      for your compiler.  Failure to do this may result in UTC (GMT) times
  25.      being wrong.  Output formatting is done using an RRRRWWWWLLLLooooccccaaaalllleeee object.  The
  26.      default locale formats according to U.S. conventions.  Note that because
  27.      the default constructor for this class creates an instance holding the
  28.      current date and time, constructing a large array of RRRRWWWWTTTTiiiimmmmeeee may be slow.
  29.  
  30.               RWTime v[5000];     // Figures out the current time 5000 times
  31.  
  32.  
  33.  
  34.  
  35.  
  36.      Those with access to the C++ Standard Library-based versions of the
  37.      TTTToooooooollllssss....hhhh++++++++ template collections should consider the following:
  38.  
  39.               // Figures out the current time just once:
  40.  
  41.  
  42.  
  43.               RWTValOrderedVector<RWTime> v(5000, RWTime());
  44.  
  45.  
  46.      Thanks to the smart allocation scheme of the standard collections, the
  47.      above declaration will result in only one call to the default constructor
  48.      followed by 5000 invocations of the copy constructor.  In the case of
  49.      RRRRWWWWTTTTiiiimmmmeeee,,,, the copy constructor amounts to an assignment of one lllloooonnnngggg to
  50.      another, resulting in faster creation than the simple array.
  51.  
  52. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  53.      Simple
  54.  
  55. EEEExxxxaaaammmmpppplllleeee
  56.      This example constructs a current time, and the time when Daylight-Saving
  57.      Time starts in the year 1990.  It then prints them out.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               #include <rw/rwtime.h>
  75.  
  76.  
  77.  
  78.               #include <rw/rwdate.h>
  79.           #include <rw/rstream.h>
  80.           main(){
  81.            RWTime t;   // Current time
  82.            RWTime d(RWTime::beginDST(1990, RWZone::local()));
  83.              cout << "Current time:         " << RWDate(t) << " " << t <<
  84.                       endl;
  85.              cout << "Start of DST, 1990:   " << RWDate(d) << " " << d <<
  86.                      endl;
  87.           }
  88.  
  89.      PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt
  90.  
  91.               Current time:         03/22/91 15:01:40
  92.           Start of DST, 1990:   05/01/90 02:00:00
  93.  
  94.  
  95.  
  96. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  97.               RRRRWWWWTTTTiiiimmmmeeee();
  98.  
  99.  
  100.      Default constructor.  Constructs a time with the present time.
  101.  
  102.               RRRRWWWWTTTTiiiimmmmeeee(const RWTime&);
  103.  
  104.  
  105.      Copy constructor.
  106.  
  107.               RRRRWWWWTTTTiiiimmmmeeee(unsigned long s);
  108.  
  109.  
  110.      Constructs a time with ssss seconds since 00:00:00 January 1, 1901 UTC.  If
  111.      ssss========0000, an invalid time is constructed.  Note that for small ssss this may be
  112.      prior to January 1, 1901 in your time zone.
  113.  
  114.               RRRRWWWWTTTTiiiimmmmeeee(unsigned hour, unsigned minute, unsigned second=0,
  115.                  const RWZone& zone = RWZone::local());
  116.  
  117.  
  118.      Constructs a time with today's date, and the specified hour, minute, and
  119.      second, relative to the time zone zzzzoooonnnneeee, which defaults to local time.
  120.  
  121.               RRRRWWWWTTTTiiiimmmmeeee(const RWDate& date, unsigned hour = 0,
  122.                  unsigned minute = 0,unsigned second = 0,
  123.                  const RWZone& = RWZone::local());
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      Constructs a time for a given date, hour, minute, and second, relative to
  141.      the time zone zzzzoooonnnneeee, which defaults to local time.  Note that the maximum
  142.      RRRRWWWWTTTTiiiimmmmeeee is much sooner than maximum RRRRWWWWDDDDaaaatttteeee.  (In fact, it is on Feb. 5,
  143.      2037 for platforms with 4-byte lllloooonnnnggggs.)  This is a consequence of the fact
  144.      that RRRRWWWWTTTTiiiimmmmeeee counts seconds while RRRRWWWWDDDDaaaatttteeee only deals with full days.
  145.  
  146.               RRRRWWWWTTTTiiiimmmmeeee(const struct tm*, const RWZone& = RWZone::local());
  147.  
  148.  
  149.      Constructs a time from the ttttmmmm____yyyyeeeeaaaarrrr, ttttmmmm____mmmmoooonnnn, ttttmmmm____mmmmddddaaaayyyy, ttttmmmm____hhhhoooouuuurrrr, ttttmmmm____mmmmiiiinnnn, and
  150.      ttttmmmm____sssseeeecccc components of the ssssttttrrrruuuucccctttt ttttmmmm argument.  These components are
  151.      understood to be relative to the time zone zzzzoooonnnneeee, which defaults to local
  152.      time.  Note that the numbering of months and years in a ssssttttrrrruuuucccctttt ttttmmmm differs
  153.      from that used in RRRRWWWWTTTTiiiimmmmeeee arguments.
  154.  
  155.               RRRRWWWWTTTTiiiimmmmeeee(const RWDate& date, const RWCString& str,
  156.                  const RWZone& zone = RWZone::local(),
  157.                  const RWLocale& locale = RWLocale::global());
  158.  
  159.  
  160.      Constructs a time for the given date, extracting the time from the string
  161.      ssssttttrrrr.  The string ssssttttrrrr should contain only the time.  The time is
  162.      understood to be relative to the time zone zzzzoooonnnneeee, which defaults to local
  163.      time.  The specified locale is used for formatting information .  Use
  164.      function iiiissssVVVVaaaalllliiiidddd(((()))) to check the results.  Note: not all time string
  165.      errors can be detected by this function.
  166.  
  167. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss
  168.               RWTime&
  169.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTime&);
  170.  
  171.  
  172.      Assignment operator.
  173.  
  174.               RWTime
  175.           ooooppppeeeerrrraaaattttoooorrrr++++++++();
  176.  
  177.  
  178.      Prefix increment operator.  Add one second to self, then return the
  179.      results.
  180.  
  181.               RWTime
  182.           ooooppppeeeerrrraaaattttoooorrrr--------();
  183.  
  184.  
  185.      Prefix decrement operator.  Subtract one second from self, then return
  186.      the results.
  187.  
  188.               RWTime
  189.           ooooppppeeeerrrraaaattttoooorrrr++++++++(int);
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      Postfix increment operator.  Add one second to self, returning the
  207.      initial value.
  208.  
  209.               RWTime
  210.           ooooppppeeeerrrraaaattttoooorrrr--------(int);
  211.  
  212.  
  213.      Postfix decrement operator.  Subtract one second from self, returning the
  214.      initial value.
  215.  
  216.               RWTime&
  217.           ooooppppeeeerrrraaaattttoooorrrr++++====(unsigned long s);
  218.  
  219.  
  220.      Add ssss seconds to self, returning self.
  221.  
  222.               RWTime&
  223.           ooooppppeeeerrrraaaattttoooorrrr----====(unsigned long s);
  224.  
  225.  
  226.      Subtract ssss seconds from self, returning self.
  227.  
  228. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  229.               RWCString
  230.           aaaassssSSSSttttrrrriiiinnnngggg(char format = ' ',const RWZone& = RWZone::local(),
  231.                    const RWLocale& = RWLocale::global()) const;
  232.  
  233.  
  234.      Returns self as a string, formatted by the RRRRWWWWLLLLooooccccaaaalllleeee argument, with the
  235.      time zone adjusted according to the RRRRWWWWZZZZoooonnnneeee argument.  Formats are as
  236.      defined by the standard C library function ssssttttrrrrffffttttiiiimmmmeeee(((()))).  The default
  237.      format is the date followed by the time: "%%%%xxxx %%%%XXXX".   The exact format of
  238.      the date and time returned is dependent upon the implementation of
  239.      ssssttttrrrrffffttttiiiimmmmeeee(((()))) available.  For more information, look under RRRRWWWWLLLLooooccccaaaalllleeee.
  240.  
  241.               RWCString
  242.           aaaassssSSSSttttrrrriiiinnnngggg(char* format,const RWZone&   = RWZone::local(),
  243.                    const RWLocale& = RWLocale::global()) const;
  244.  
  245.  
  246.      Returns self as a string, formatted by the RRRRWWWWLLLLooooccccaaaalllleeee argument, with the
  247.      time zone adjusted according to the RRRRWWWWZZZZoooonnnneeee argument.  Formats are as
  248.      defined by the standard C library function ssssttttrrrrffffttttiiiimmmmeeee(((()))).
  249.  
  250.               RWBoolean
  251.           bbbbeeeettttwwwweeeeeeeennnn(const RWTime& a, const RWTime& b) const;
  252.  
  253.  
  254.      Returns TTTTRRRRUUUUEEEE if RRRRWWWWTTTTiiiimmmmeeee is between aaaa and bbbb, inclusive.
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.               size_t
  273.           bbbbiiiinnnnaaaarrrryyyySSSSttttoooorrrreeeeSSSSiiiizzzzeeee() const;
  274.  
  275.  
  276.      Returns the number of bytes necessary to store the object using the
  277.      global function
  278.  
  279.               RWFile& operator<<(RWFile&, const RWTime&);
  280.  
  281.  
  282.  
  283.               int
  284.           ccccoooommmmppppaaaarrrreeeeTTTToooo(const RWTime* t) const;
  285.  
  286.  
  287.      Comparison function, useful for sorting times.  Compares self to the
  288.      RRRRWWWWTTTTiiiimmmmeeee pointed to by tttt and returns:
  289.  
  290.                   0  if self == *tttt;
  291.               1  if self > *tttt;
  292.              -1  if self < *tttt;
  293.  
  294.  
  295.  
  296.  
  297.               void
  298.           eeeexxxxttttrrrraaaacccctttt(struct tm*,const RWZone& = RWZone::local()) const;
  299.  
  300.  
  301.      Fills all members of the ssssttttrrrruuuucccctttt ttttmmmm argument, adjusted to the time zone
  302.      specified by the RRRRWWWWZZZZoooonnnneeee argument.  If the time is invalid, the ssssttttrrrruuuucccctttt ttttmmmm
  303.      members are all set to -1.  Note that the encoding of ssssttttrrrruuuucccctttt ttttmmmm members
  304.      is different from that used in RRRRWWWWTTTTiiiimmmmeeee and RRRRWWWWDDDDaaaatttteeee functions.
  305.  
  306.               unsigned
  307.           hhhhaaaasssshhhh() const;
  308.  
  309.  
  310.      Returns a suitable hashing value.
  311.  
  312.               unsigned
  313.           hhhhoooouuuurrrr(const RWZone& zone = RWZone::local()) const;
  314.  
  315.  
  316.      Returns the hour, adjusted to the time zone specified.
  317.  
  318.               unsigned
  319.           hhhhoooouuuurrrrGGGGMMMMTTTT() const;
  320.  
  321.  
  322.      Returns the hour in UTC (GMT).
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               RWBoolean
  339.           iiiissssDDDDSSSSTTTT(const RWZone& zone = RWZone::local()) const;
  340.  
  341.  
  342.      Returns TTTTRRRRUUUUEEEE if self is during Daylight-Saving Time in the time zone
  343.      given by zzzzoooonnnneeee, FFFFAAAALLLLSSSSEEEE otherwise.
  344.  
  345.               RWBoolean
  346.           iiiissssVVVVaaaalllliiiidddd() const;
  347.  
  348.  
  349.      Returns TTTTRRRRUUUUEEEE if this is a valid time, FFFFAAAALLLLSSSSEEEE otherwise.
  350.  
  351.               RWTime
  352.           mmmmaaaaxxxx(const RWTime& t) const;
  353.  
  354.  
  355.      Returns the later time of self or tttt.
  356.  
  357.               RWTime
  358.           mmmmiiiinnnn(const RWTime& t) const;
  359.  
  360.  
  361.      Returns the earlier time of self or tttt.
  362.  
  363.               unsigned
  364.           mmmmiiiinnnnuuuutttteeee(const RWZone& zone = RWZone::local()) const;
  365.  
  366.  
  367.      Returns the minute, adjusted to the time zone specified.
  368.  
  369.               unsigned
  370.           mmmmiiiinnnnuuuutttteeeeGGGGMMMMTTTT() const;
  371.  
  372.  
  373.      Returns the minute in UTC (GMT).
  374.  
  375.               unsigned
  376.           sssseeeeccccoooonnnndddd() const;
  377.  
  378.  
  379.      Returns the second; local time or UTC (GMT).
  380.  
  381.               unsigned long
  382.           sssseeeeccccoooonnnnddddssss() const;
  383.  
  384.  
  385.      Returns the number of seconds since 00:00:00 January 1, 1901 UTC.
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404. Static Public Member Functions
  405.               static RWTime
  406.           bbbbeeeeggggiiiinnnnDDDDSSSSTTTT(unsigned year,
  407.                    const RWZone& zone = RWZone::local());
  408.  
  409.  
  410.      Return the start of Daylight-Saving Time (DST) for the given year, in the
  411.      given time zone.  Returns an "invalid time" if DST is not observed in
  412.      that year and zone.
  413.  
  414.               static RWTime
  415.           eeeennnnddddDDDDSSSSTTTT(unsigned year, const RWZone& = RWZone::local());
  416.  
  417.  
  418.      Return the end of Daylight-Saving Time for the given year, in the given
  419.      time zone.  Returns an "invalid time" if DST is not observed in that year
  420.      and zone.
  421.  
  422.               static unsigned
  423.           hhhhaaaasssshhhh(const RWTime& t);
  424.  
  425.  
  426.      Returns the hash value of tttt as returned by tttt....hhhhaaaasssshhhh(((()))).
  427.  
  428.               static RWTime
  429.           nnnnoooowwww();
  430.  
  431.  
  432.      Returns the present time.
  433.  
  434. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss
  435.               RWTime
  436.           ooooppppeeeerrrraaaattttoooorrrr++++(const RWTime& t, unsigned long s);
  437.           RWTime
  438.           ooooppppeeeerrrraaaattttoooorrrr++++(unsigned long s, const RWTime& t);
  439.  
  440.  
  441.      Returns an RRRRWWWWTTTTiiiimmmmeeee ssss seconds greater than tttt.
  442.  
  443.               RWTime
  444.           ooooppppeeeerrrraaaattttoooorrrr----(const RWTime& t, unsigned long s);
  445.  
  446.  
  447.      Returns an RRRRWWWWTTTTiiiimmmmeeee ssss seconds less than tttt.
  448.  
  449.               RWBoolean
  450.           ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTime& t1, const RWTime& t2);
  451.  
  452.  
  453.      Returns TTTTRRRRUUUUEEEE if tttt1111 is less than tttt2222.
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  467.  
  468.  
  469.  
  470.               RWBoolean
  471.           ooooppppeeeerrrraaaattttoooorrrr<<<<====(const RWTime& t1, const RWTime& t2);
  472.  
  473.  
  474.      Returns TTTTRRRRUUUUEEEE if tttt1111 is less than or equal to tttt2222.
  475.  
  476.               RWBoolean
  477.           ooooppppeeeerrrraaaattttoooorrrr>>>>(const RWTime& t1, const RWTime& t2);
  478.  
  479.  
  480.      Returns TTTTRRRRUUUUEEEE if tttt1111 is greater than tttt2222.
  481.  
  482.               RWBoolean
  483.           ooooppppeeeerrrraaaattttoooorrrr>>>>====(const RWTime& t1, const RWTime& t2);
  484.  
  485.  
  486.      Returns TTTTRRRRUUUUEEEE if tttt1111 is greater than or equal to tttt2222.
  487.  
  488.               RWBoolean
  489.           ooooppppeeeerrrraaaattttoooorrrr========(const RWTime& t1, const RWTime& t2);
  490.  
  491.  
  492.      Returns TTTTRRRRUUUUEEEE if tttt1111 is equal to tttt2222.
  493.  
  494.               RWBoolean
  495.           ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWTime& t1, const RWTime& t2);
  496.  
  497.  
  498.      Returns TTTTRRRRUUUUEEEE if tttt1111 is not equal to tttt2222.
  499.  
  500.               ostream&
  501.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(ostream& s, const RWTime& t);
  502.  
  503.  
  504.      Outputs the time tttt on oooossssttttrrrreeeeaaaammmm ssss, according to the locale imbued in the
  505.      stream (see class RRRRWWWWLLLLooooccccaaaalllleeee), or by RRRRWWWWLLLLooooccccaaaalllleeee::::::::gggglllloooobbbbaaaallll(((()))) if none.
  506.  
  507.               RWvostream&
  508.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream&, const RWTime& t);
  509.           RWFile&
  510.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile&,     const RWTime& t);
  511.  
  512.  
  513.      Saves RRRRWWWWTTTTiiiimmmmeeee tttt to a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively.
  514.  
  515.               RWvistream&
  516.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream&, RWTime& t);
  517.           RWFile&
  518.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile&,     RWTime& t);
  519.  
  520.  
  521.      Restores an RRRRWWWWTTTTiiiimmmmeeee into tttt from a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively,
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))                                                      RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++))))
  533.  
  534.  
  535.  
  536.      replacing the previous contents of tttt.
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.